﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CUiMFSetPlacementOriginDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.ModularFixture;

public class CUiMFSetPlacementOriginDlg : TxForm
{
  private bool m_isValidFrame;
  private TxFrame m_frame;
  private CApMFPrototypeGridRow m_prototypeGridRow;
  private TxTransformation m_location;
  private IContainer components;
  private Label label1;
  private TextBox m_resourceNameTextBox;
  private Label label2;
  private TxFrameEditBoxCtrl m_placementOriginFrameEditBox;
  private Button m_OK;
  private Button m_cancel;

  internal CUiMFSetPlacementOriginDlg(
    CApMFPrototypeGridRow prototypeGridRow,
    TxTransformation location)
  {
    this.InitializeComponent();
    this.m_prototypeGridRow = prototypeGridRow;
    this.m_location = location;
    this.InitFields();
    this.m_placementOriginFrameEditBox.ListenToPick = true;
    this.m_placementOriginFrameEditBox.Focus();
  }

  private void InitFields()
  {
    this.m_resourceNameTextBox.Text = this.m_prototypeGridRow.Name;
    if (!TxTransformation.op_Inequality(this.m_prototypeGridRow.PlacementOrigin, (TxTransformation) null))
      return;
    this.m_placementOriginFrameEditBox.SetLocation(this.m_prototypeGridRow.PlacementOrigin);
    this.m_isValidFrame = true;
    this.CreateFrameInGraphicViewer(this.m_prototypeGridRow.PlacementOrigin);
  }

  private void m_OK_Click(object sender, EventArgs e)
  {
    this.m_prototypeGridRow.PlacementOrigin = !this.m_isValidFrame ? (TxTransformation) null : this.m_placementOriginFrameEditBox.GetLocation();
    this.DeleteFrame();
    ((Form) this).Close();
  }

  private void m_placementOriginFrameEditBox_Picked(
    object sender,
    TxFrameEditBoxCtrl_PickedEventArgs args)
  {
    TxTransformation currentLocation = TxTransformation.op_Multiply(this.m_location.Inverse, args.Location);
    this.m_placementOriginFrameEditBox.SetLocation(currentLocation);
    this.CreateFrameInGraphicViewer(currentLocation);
  }

  private void m_placementOriginFrameEditBox_ValidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_ValidFrameSetEventArgs args)
  {
    this.m_isValidFrame = true;
    this.CreateFrameInGraphicViewer(this.m_placementOriginFrameEditBox.GetLocation());
  }

  private void m_placementOriginFrameEditBox_InvalidFrameSet(
    object sender,
    TxFrameEditBoxCtrl_InvalidFrameSetEventArgs args)
  {
    this.m_isValidFrame = false;
    this.DeleteFrame();
  }

  private void m_cancel_Click(object sender, EventArgs e)
  {
    this.DeleteFrame();
    ((Form) this).Close();
  }

  private void CreateFrameInGraphicViewer(TxTransformation currentLocation)
  {
    this.DeleteFrame();
    this.m_frame = TxFrameEx.CreateFrame(new TxFrameCreationDataEx("placementOrigin", TxTransformation.op_Multiply(this.m_location, currentLocation), true));
    TxApplication.RefreshDisplay();
  }

  private void DeleteFrame()
  {
    if (!TxFrame.op_Inequality(this.m_frame, (ITxObject) null))
      return;
    this.m_frame.Delete();
    this.m_frame = (TxFrame) null;
    TxApplication.RefreshDisplay();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMFSetPlacementOriginDlg));
    this.label1 = new Label();
    this.m_resourceNameTextBox = new TextBox();
    this.label2 = new Label();
    this.m_placementOriginFrameEditBox = new TxFrameEditBoxCtrl();
    this.m_OK = new Button();
    this.m_cancel = new Button();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.label1, "label1");
    this.label1.Name = "label1";
    componentResourceManager.ApplyResources((object) this.m_resourceNameTextBox, "m_resourceNameTextBox");
    this.m_resourceNameTextBox.Name = "m_resourceNameTextBox";
    this.m_resourceNameTextBox.ReadOnly = true;
    componentResourceManager.ApplyResources((object) this.label2, "label2");
    this.label2.Name = "label2";
    this.m_placementOriginFrameEditBox.EnableRelativeToWorkingFrameCoordinates = true;
    this.m_placementOriginFrameEditBox.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.m_placementOriginFrameEditBox, "m_placementOriginFrameEditBox");
    ((Control) this.m_placementOriginFrameEditBox).Name = "m_placementOriginFrameEditBox";
    this.m_placementOriginFrameEditBox.ValidFrameSet += new TxFrameEditBoxCtrl_ValidFrameSetEventHandler(this.m_placementOriginFrameEditBox_ValidFrameSet);
    this.m_placementOriginFrameEditBox.Picked += new TxFrameEditBoxCtrl_PickedEventHandler(this.m_placementOriginFrameEditBox_Picked);
    this.m_placementOriginFrameEditBox.InvalidFrameSet += new TxFrameEditBoxCtrl_InvalidFrameSetEventHandler(this.m_placementOriginFrameEditBox_InvalidFrameSet);
    componentResourceManager.ApplyResources((object) this.m_OK, "m_OK");
    this.m_OK.Name = "m_OK";
    this.m_OK.UseVisualStyleBackColor = true;
    this.m_OK.Click += new EventHandler(this.m_OK_Click);
    this.m_cancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.m_cancel, "m_cancel");
    this.m_cancel.Name = "m_cancel";
    this.m_cancel.UseVisualStyleBackColor = true;
    this.m_cancel.Click += new EventHandler(this.m_cancel_Click);
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_cancel;
    ((Control) this).Controls.Add((Control) this.m_cancel);
    ((Control) this).Controls.Add((Control) this.m_OK);
    ((Control) this).Controls.Add((Control) this.m_placementOriginFrameEditBox);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.m_resourceNameTextBox);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiMFSetPlacementOriginDlg);
    ((Form) this).ShowIcon = false;
    ((Form) this).TopMost = true;
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
